<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!--view 层-->
<div id="app">
    <todo>
        <todo-title slot="todo-title" :titles="title"></todo-title>
        <todo-items slot="todo-items" v-for="(items,index) in todoItems"
                    v-bind:item="items"
                    v-bind:index="index"
                    v-on:remove="removeItems(index)">
        </todo-items>
    </todo>

</div>
<script src="vue.js"></script>
<script>
    //slot插槽
    Vue.component("todo",{
        template: '<div>\
                        <slot name="todo-title"></slot>\
                        <ul>\
                            <slot name="todo-items"></slot>\
                        </ul>\
                   </div>'
    });
    Vue.component("todo-title",{
        props:['titles'],
        template: '<div>{{titles}}</div>'


    });
    Vue.component("todo-items",{
        props: ['item','index'],
        template: '<li>{{index}}---{{item}} <button @click="remove">删除</button></li>',
        //只能绑定当前的方法
        methods :{
            remove: function (index){
                //参数传递 自定义事件
                this.$emit('remove',index)
            }
        }
    });
    var vm=new Vue({
        el: "#app",
        data: {
            title:"cljh列表",
            todoItems:['cljh学java','cljh学前端','cljh学Linux']
        },
        methods: {
            removeItems: function (index){
                console.log("删除了："+this.todoItems[index]+"ok")
                this.todoItems.splice(index,1);//删除一个元素
            }
        }

    });
</script>
</body>
</html>